package com.cloud.netty.handler;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;

/**
 * @program: netty
 * @description:
 * @author: Cloud
 * @create: 2022/4/13 11:16:48
 */
public class MyServerHandler extends SimpleChannelInboundHandler<Long> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Long msg) {
        System.out.println("从客户端："+ctx.channel().remoteAddress()+" 读取到long "+msg);
        System.out.println("从服务发送数据到客户端地址是: "+ctx.channel().remoteAddress());
        ctx.writeAndFlush(123456l);
    }


    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }
}
